package com.ruoyi.system.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ruoyi.common.core.domain.entity.SysRole;

@Repository
public interface SysRoleDAO
		extends JpaRepository<SysRole, String>, JpaSpecificationExecutor<SysRole>, Serializable {

	@Modifying
	@Query(value = " update sys_role set status = ?2,update_time = sysdate() where role_id=?1 ", nativeQuery = true)
	public int updateRoleStatus(String roleId, String status);
	
	
	
	@Query(value = "select distinct r.* from sys_role r "
			+ " left join sys_role_user ur on ur.role_id = r.role_id "
			+ " WHERE r.del_flag = '0' and ur.user_id = ?1  ", nativeQuery = true)
	public List<SysRole> selectRolePermissionByUserId(String userId);
	
	@Query(value = " select r.* from sys_role r "
			+ " left join sys_role_user ur on ur.role_id = r.role_id "
			+ " left join sys_user u on u.user_id = ur.user_id " + " where u.user_id =?1 ", nativeQuery = true)
	public List<SysRole> selectRoleIdListByUserId(String userId);

}
